package boogui.movie;

import java.sql.Connection;
import java.sql.PreparedStatement;

import boogui.db.BooguiDAO;
import boogui.db.IBooguiDAO;
import boogui.member.MemberVO;


public class ReservationDAO implements IReservationDAO{
	
	private IBooguiDAO bd = null;
	
	private String insertSQL = "insert into resurvation values(exam.nextval, ?, ?, ?, ?, ?, ?)";
	private String selectSQL = "select * from RESURVATION order by reserveno";
	private String deleteSQL = "delete resurvaion where memno = ?";
	
	private MemberVO mbvo = new MemberVO();
	private MovieVO mvvo = new MovieVO();
	private MovieAreaVO mavo = new MovieAreaVO();
	private S_MovieSeatDialog mbs = new S_MovieSeatDialog();
	private int people;
	private int price;
	
	public ReservationDAO() {
		bd = new BooguiDAO();
	}
	
	@Override
	public boolean insertReserv() {		
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
		
		try{
			conn = bd.openDatabase();
			pstmt = conn.prepareStatement(insertSQL);
			pstmt.setString(1, mbvo.getMemno());
			pstmt.setString(2, mvvo.getMovno());
			pstmt.setString(3, mavo.getCineno());
			//people = sc.nextInt();
			pstmt.setInt(4, people);
			//pstmt.setInt(5, mbs.getInt());
			price = people * 8000;
			pstmt.setInt(6, price);
			pstmt.executeUpdate();
			result = true;
			
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			bd.closeDatabase(conn, pstmt, null);
		}
		
		return result;
	}

	@Override
	public boolean deleteReserv() {
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
		
		try{
			conn = bd.openDatabase();
			pstmt = conn.prepareStatement(deleteSQL);
			pstmt.setString(1, mbvo.getMemno());
			int cnt = pstmt.executeUpdate();
			
			if(cnt == 0)System.out.println("");
			
			result = true;
			
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			bd.closeDatabase(conn, pstmt, null);
		}
		
		return result;
	}
	
}
